# @app.route("/login")
# def login():
#     name = request.args.get("username")
#     session["name"] = name  # 第一次使用session  会向客户端 发送一个cookie (sesson,sessionID)
#     return "登录成功 用户名是: %s" % name
#
#
# @app.route("/home")
# def home():
#     name = "匿名"
#     name = session.get("name")  # 根据请求中携带的cookie 找到sessionID  找到对应的session对象
#     return "我是首页,当前用户是: {}".format(name)


from flask import Flask, session, request,jsonify

app = Flask(__name__)

app.config.from_pyfile("config.py")


@app.route("/login")
def login():
    session.permanent = True
    name = request.args.get("username")
    session["name"] = name
    return "登录成功，用户名是：{}".format(name)


@app.route("/home")
def home():
    name = session.get("name")
    return "我是首页，当前用户是：{}".format(name)


@app.route("/logout")
def logout():
    session.pop("name")
    return "注销登录"


if __name__ == '__main__':
    app.run()
